/* 
 * File:   BaseServerProtocol.cpp
 * Author: wilq
 * 
 * Created on June 14, 2012, 10:34 AM
 */

#include "BaseServerProtocol.h"

BaseServerProtocol::BaseServerProtocol(socket_ptr s) : NetworkProtocol(s){
}

string BaseServerProtocol::_Get_String(const NetworkPacket &packet, uint32_t position)
{
    char buffor[256];
	buffor[0] = 0;
    packet.Get_String(position, buffor, 255);
	buffor[255] = 0;
    return string(buffor);
}

void BaseServerProtocol::_Push_File(NetworkPacket &packet, File file)
{
    packet.Push_U32(file.id);
    packet.Push_U32(file.parentId);
    packet.Push_U32(file.ownerGroupId);
    packet.Push_U32(file.ownerUserId);
    packet.Push_U32(file.storageId);

    packet.Push_U32(file.rights);
    packet.Push_U32(file.size);

    packet.Push_U64(file.createDate);
    packet.Push_U64(file.lastAccesDate);
    packet.Push_U64(file.lastModificationDate);

    packet.Push_String(file.link.c_str());
    packet.Push_String(file.name.c_str());
}

void BaseServerProtocol::_Push_Folder(NetworkPacket &packet, Folder folder)
{
    packet.Push_U32(folder.id);
    packet.Push_U32(folder.parentId);
    packet.Push_U32(folder.ownerGroupId);
    packet.Push_U32(folder.ownerUserId);
    packet.Push_U32(folder.storageId);

    packet.Push_U32(folder.rights);

    packet.Push_U64(folder.createDate);

    packet.Push_String(folder.link.c_str());
    packet.Push_String(folder.name.c_str());
}



void BaseServerProtocol::_Push_User(NetworkPacket &packet, User user)
{
    packet.Push_U32(user.id);
    packet.Push_String(user.name.c_str());
    packet.Push_U32(user.createDate);
    packet.Push_U32(user.lastAccessDate);
    packet.Push_U32(user.rights);
}

void BaseServerProtocol::_Push_Storage(NetworkPacket &packet, Storage storage)
{
    packet.Push_U32(storage.id);
    packet.Push_String(storage.name.c_str());
    packet.Push_U32(storage.createDate);
    packet.Push_U32(storage.lastAccessDate);
}

void BaseServerProtocol::_Push_Group(NetworkPacket &packet, Group group)
{
    packet.Push_U32(group.id);
    packet.Push_String(group.name.c_str());
    packet.Push_U32(group.createDate);
    packet.Push_U32(group.baseRights);
}